<?php

namespace App\Modules\LuckDraw\Strategy;

use App\Modules\LuckDraw\Lib\StrLib;

class StrategyFactory {
    //获取一个奖品实例
    public static function get(int $luckId, int $userId, ?object $strategyData, object $pool) : ?StrategyInterface {
        if (empty($userId) || empty($strategyData) || empty($strategyData->name) || empty($pool)) {
            return null;
        }

        $className = __NAMESPACE__ . '\\' . StrLib::camelize($strategyData->name) . 'Strategy';
        if(class_exists($className)){
            return new $className($luckId, $userId, $strategyData->ext, $pool);
        }
        return null;
    }

    public static function getStategyClassName(string $strategyName):?string{
        $className = __NAMESPACE__ . '\\' . StrLib::camelize($strategyName) . 'Strategy';
        if(class_exists($className)){
            return $className;
        }
        return null;
    }
}